package br.com.bancodados.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import br.com.bancodados.model.Carro;
import br.com.bancodados.ui.R;

public class CarrosAdapter extends BaseAdapter{
	private Context mContext;
	private ArrayList<Carro> carros;
	private LinearLayout ll;
	private TextView tvMarca;
	private TextView tvModelo;
	private TextView tvPlaca;
	private TextView tvCor;
	
	
	public CarrosAdapter(Context context, ArrayList<Carro> carros) {
		this.mContext = context;
		this.carros = carros;
	}

	@Override
	public int getCount() {
		if (carros == null) {
			return 0;
		}
		return carros.size();
	}

	@Override
	public Object getItem(int position) {
		if (carros == null) {
			return position;
		}
		return carros.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ll = (LinearLayout) LayoutInflater.from(this.mContext).inflate(
				R.layout.list_carros_layout, null);

		tvMarca = (TextView) ll.findViewById(R.id.tv_marca);
		tvModelo = (TextView) ll.findViewById(R.id.tv_modelo);
		tvPlaca = (TextView) ll.findViewById(R.id.tv_placa);
		tvCor = (TextView) ll.findViewById(R.id.tv_cor);
		
		tvMarca.setText(carros.get(position).getMarca());
		tvModelo.setText(carros.get(position).getModelo());
		tvPlaca.setText(carros.get(position).getPlaca());
		tvCor.setText(carros.get(position).getCor());

		ll.setTag(carros.get(position));
		
		return ll;
	}


}
